$(function() {
	jQuery.validator.addMethod("isMoney", function(value, element) {   
		return this.optional(element) || /^(([1-9]\d*)(\.\d{1,5})?)$|(0\.0?([1-9]\d?))$/.test(value);   
	}, "请正确填写金额");
	
	$("#add_goods_form").validate({
		errorPlacement:function(error,element) {  
			element.parent().find(".verror").html(error);
		},
		rules:{
			"goodsInfo.goodsNo":{
				required:true,
				rangelength: [4, 20],
				remote: {
					url: base + "admin/goods/checkGoodsNo.action", 
					type: "POST", 
					data: {"goodsInfo.id": ($("#goodsInfo_id").val()), "goodsInfo.goodsNo": ($("#goodsInfo.goodsNo").val())}
				}
			},
			"goodsInfo.goodsName":{
				required:true,
				rangelength: [2, 20]
			},
			"goodsInfo.specification":{
				required:true,
				rangelength: [2, 20]
			},
			"goodsInfo.unitPrice":{
				required:true,
				isMoney:true
			},
			"goodsInfo.stock":{
				required:true,
				number: true
			}
		},
		messages:{
			"goodsInfo.goodsNo": {
				required: "请输入商品编号", 
				rangelength:"长度不能少于{0}和大于{1}个字符",
				remote: "该编号已存在"
			},
			"goodsInfo.goodsName": {
				required: "请输入商品名称",
				rangelength: "长度不能少于{0}和大于{1}个字符"
			},
			"goodsInfo.specification":{
				required: "请输入商品规格",
				rangelength: "长度不能少于{0}和大于{1}个字符"
			},
			"goodsInfo.unitPrice": {
				required: "请输入商品单价", 
				isMoney: "金额格式不正确"
			},
			"goodsInfo.stock": {
				required: "请输入商品库存量",
				number: "请输入整数值"
			} 
		}
	});
});